//
//  UILabel+Space.swift
//  aquariumstudio
//
//  Created by zj on 2022/11/2.
//  Copyright © 2022 LXF. All rights reserved.
//

import UIKit

public extension UILabel{
    
//    + (void)changeLineSpaceForLabel:(UILabel *)label WithSpace:(float)space {
//        NSString *labelText = label.text;
//        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
//        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//        [paragraphStyle setLineSpacing:space];
//        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
//        label.attributedText = attributedString;
//        [label sizeToFit];
//    }
    func changeLineSpace(space:CGFloat){
        guard let text = text else { return }
        let mas = NSMutableAttributedString.init(string: text)
        let ps = NSMutableParagraphStyle.init()
        ps.lineSpacing = space;
        mas.addAttribute(NSAttributedString.Key.paragraphStyle, value: ps, range: NSRange.init(location: 0, length: text.count))
        attributedText = mas
        sizeToFit()
    }
    func changeWordSpace(space:CGFloat,lineSpacing:CGFloat? = nil){
        guard let text = text else { return }
        let mas = NSMutableAttributedString.init(string: text,attributes: [NSAttributedString.Key.kern : space])
        let ps = NSMutableParagraphStyle.init()
        if let lineSpacing = lineSpacing {
            ps.lineSpacing = lineSpacing;
        }

        mas.addAttribute(NSAttributedString.Key.paragraphStyle, value: ps, range: NSRange.init(location: 0, length: text.count))
        attributedText = mas
        sizeToFit()
    }
//    + (void)changeWordSpaceForLabel:(UILabel *)label WithSpace:(float)space {
//        NSString *labelText = label.text;
//        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText attributes:@{NSKernAttributeName:@(space)}];
//        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
//        label.attributedText = attributedString;
//        [label sizeToFit];
//    }
 

    
}
